Dragging a Popup Window

level: intermediate

by Brent Thorn

Home

LB Browser

4.03 Review

LED Display

Sprite Byte Masks

API Corner

Ini Files

Registration Keys

Eddie Fonts

Dragging a Popup

Random Audio Player

Eddie

Submissions

Index


Brent is sharing two demos that show how to allow the user to drag a popup window. A popup has no titlebar, so it requires a little extra coding to make this possible.

Demo One

Brent has released this code into the public domain with the following explanation.

This demo works by trapping a left-drag inside the GRAPHICBOX, then tricks the dialog window into believing you are dragging its (non-existent) title bar. The benefit of using this technique (over calling the MoveWindow API inside a similar event handler) is that this automatically takes into account the user's preference for "show window contents while dragging."

Code

NoMainWin

WindowWidth = 400
WindowHeight = 300
UpperLeftX = (DisplayWidth - WindowWidth) / 2
UpperLeftY = (DisplayHeight - WindowHeight) / 2

GraphicBox #demo.gfx, 0, 0, WindowWidth, WindowHeight
StyleBits #demo.gfx, 0, _WS_BORDER, 0, 0

Open "Demo" For Dialog_Popup As #demo

#demo "TrapClose demo.Close"
#demo.gfx "When leftButtonMove demo.gfx.leftButtonMove"
#demo.gfx "Down; Fill ButtonFace; BackColor ButtonFace"
#demo.gfx "\\\ Try dragging me around!"
#demo.gfx "\\ Press Alt+F4 to close."
#demo.gfx "Flush"

Wait

Sub demo.Close demo$
Close #demo$
End
End Sub

Sub demo.gfx.leftButtonMove demo.gfx$, X, Y
demo$ = Word$(demo.gfx$, 1, ".")

CallDLL #user32, "ReleaseCapture", _
r As void

hWnd = HWnd(#demo$)
CallDLL #user32, "SendMessageA", _
hWnd As ULong, _
_WM_NCLBUTTONDOWN As ULong, _
_HTCAPTION As Long, _
0 As Long, _
r As Long
End Sub 


Demo Two

Brent has also written a demo that uses WMLiberty.DLL to subclass a window and allow it to be dragged. The code is included in the zipped archive of this issue, because you must have the WMLiberty.DLL in the folder with the code in order to run it. Here is Brent's explanation of the second demo:

' This demo uses the WMLiberty DLL to trap the mouse's

' left-click in a popup-type window as a means to move

' the window around on the screen.


Home

LB Browser

4.03 Review

LED Display

Sprite Byte Masks

API Corner

Ini Files

Registration Keys

Eddie Fonts

Dragging a Popup

Random Audio Player

Eddie

Submissions

Index